home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / com / internet / nos / nosshell / source / nos.c
Encoding:
C/C++ Source or Header  |  1996-01-01  |  2.4 KB  |  101 lines

  1. /******************************************************************
  2. *                       NOS.C
  3. *
  4. *       Program extracting IP-address from the STIK config file:
  5. *            C:\STIK_CFG\CONFIG.SAV
  6. *
  7. *       Then posts it into 'STARTUP.NOS'
  8. *       
  9. *       The program is named 'NOS.TTP' to trick 'OASIS' to fork
  10. *       this one instead of the actual 'NOS.TTP'.
  11. *       This program forks the real 'NOS' which has to be renamed
  12. *       to 'NOSEXT.TTP'.
  13. *
  14. *        ----------------------------------------------------------
  15. *        1995-12-31        Relative pathways used instead of absolute
  16. *
  17. *******************************************************************/
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22.  
  23. #define TRUE    1
  24. #define FALSE   0
  25.  
  26. void main(argc, argv)
  27. int     argc;
  28. char    *argv[];
  29. {
  30.     FILE    *fp;                    /* file pointer */
  31.     
  32.     long    buf;                    /* buffer */
  33.     
  34.     char    IP[50];                 /* IP-address string */
  35.  
  36.     static char line[200][100];     /* input text line from file */
  37.     
  38.     short   fld1, fld2, fld3, fld4,
  39.             i, j,
  40.             insert;
  41.  
  42.     
  43.  
  44.  
  45.     /* get IP from 'STIK' config file */
  46.     if ((fp = fopen("C:\\STIK_CFG\\CONFIG.SAV", "rb")) == NULL) {
  47.         exit(0);
  48.     }
  49.     fread(&buf, sizeof(long), 1, fp);
  50.     fclose(fp);
  51.     if ((fp = fopen("C:\\STIK_CFG\\CONFIG.SAV", "rb")) == NULL) {
  52.         exit(0);
  53.     }
  54.     fread(&buf, sizeof(long), 1, fp);
  55.     fclose(fp);
  56.     
  57.     /* extract IP address byte fields */
  58.     fld1 = buf          & 0xFF;
  59.     fld2 = (buf >> 8)   & 0xFF;
  60.     fld3 = (buf >> 16)  & 0xFF;
  61.     fld4 = (buf >> 24)  & 0xFF;
  62.  
  63.     /* build IP address string */
  64.     sprintf(IP, "ip addr [%d.%d.%d.%d]\n", fld4, fld3, fld2, fld1);
  65.     
  66.  
  67.     if ((fp = fopen("STARTUP.NOS", "r+")) == NULL) {
  68.         printf("Failed to open \"STARTUP.NOS\"\n");
  69.         exit(0);
  70.     }
  71.  
  72.     insert = FALSE;
  73.     for (i = 0; i < 200; i++) {
  74.         if ((fgets(line[i], 100, fp)) == NULL) {
  75.             break;
  76.         }
  77.         if (!strncmp(line[i], "ip addr ", 8)) {
  78.             strcpy(line[i], IP);
  79.         }
  80.     }
  81.  
  82.     fclose(fp);
  83.  
  84.     if ((fp = fopen("STARTUP.NOS", "w")) == NULL) {
  85.         printf("Failed to open \"STARTUP.NOS\"\n");
  86.         exit(0);
  87.     }
  88.  
  89.     j = 0;
  90.     for (; i >= 0; --i) {
  91.         fputs(line[j++], fp);
  92.     }
  93.  
  94.     fclose(fp);
  95.  
  96.     strcpy(argv[0], "NOSEXT.TTP");
  97.     forkv(argv[0], argv);
  98.  
  99.     exit(0);
  100. }
  101.